package cn.jee.jsp;

import cn.jee.jsp.util.JdbcUtil;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
@WebServlet("/updateClazz")
public class UpdateClazzServlet extends HttpServlet {
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    doPost(req, resp);
  }

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String id = req.getParameter("id");
    String name=req.getParameter("name");

    String sql="update clazz set name=? where id=?";
    Object[] args={name,id};
    int row=JdbcUtil.update(sql,args);
    HttpSession session=req.getSession();
    session.setAttribute("clazz_msg",row>0?"修改成功":"修改失败");
    resp.sendRedirect(req.getContextPath()+"/showClazzes");
  }
}
